home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Amiga Plus 2004 #2
/
Amiga Plus CD - 2004 - No. 02.iso
/
AmiSoft
/
Util
/
misc
/
ChkIndex.lha
/
ChkIndex
/
ChkIndex.s
< prev
next >
Wrap
Text File
|
2003-12-26
|
58KB
|
2,053 lines
*****************************************************************************
* *
* PROGRAM: ChkIndex *
* VERSION: 2.0 *
* SOURCE CODE: 48 (22.10.2003) *
* DATE: 22.12.2002 - 20.07.2003 *
* LANGUAGE: Assembler (DevPac V3.14) *
* SYSTEM: A1200 KS 40.68 WB 40.42 2MB chip 64MB fast 68030/50mhz *
* *
* AUTHOR: Joerg Riemer 14167 Berlin/SchottmuellerStr.107/Germany *
* EMAIL: joerg_riemer@freenet.de / mission@cs.tu-berlin.de *
* *
* COMMENT: search the aminet index_file for identical entries *
* *
* TEMPLATE: INDEXFILE/A path/name (index)file *
* OUTPUTFILE/A path/name outputfile for equal entries *
* *
* WS=WRITESORTED/K save sorted (index)file *
* SKIP/N skip # of lines (index header = 8 lines) *
* C=CASE/S sort case sensitive *
* R=REVERSE/S sort reverse *
* S=SLOW/S use less memory; save files line by line *
* *
* OPTION: To make ChkIndex as short as possible, set BSS_Section *
* to NULL and use StripHunk to generate a Code_BSS-segment. *
* spares some bytes! but for anybody don't know what this *
* means: "leave it as it is" *
* *
* StripHunk is available at AmiNet dev/misc/... *
* *
* for suggestions, hints/tips, and/or questions, *
* send an email! (see above for address) *
* *
*****************************************************************************
* opt d+
* opt o+
BSS_Section set 1
*****************************************************************************
output ram:ChkIndex
*****************************************************************************
*
* small statistic (checked while debugging version 1.9.32)
*
* aminet indexfile size: 5.277.715 lines: 71.861 date: 16.3.2003
*
* GetIFile = 2.017744 sec. (open file; allocmem; read file)
* CreateEList = 2.613314 sec. (allocmem; create list for all lines)
* SortEList = 6.436765 sec. (sort list [quicksort])
* GetMEntries = 3.829775 sec. (search for multiple entries; write lines)
* -----------------------------
* 14.897598 sec.
* -----------------------------
* WriteSFile = 14.691603 sec. (write sorted file [line by line])
* -----------------------------
* 29.589201 sec.
*
************************************************ exec definitions ***********
_LVOOpenLibrary equ -552
_LVOCloseLibrary equ -414
_LVOAllocMem equ -198
_LVOFreeMem equ -210
_LVOCopyMem equ -624
_LVOCacheClearU equ -636
************************************************ dos definitions ************
_LVOOutput equ -060
_LVOIoErr equ -132
_LVOFPutC equ -312
_LVOFPuts equ -342
_LVOSetIoErr equ -462
_LVOPrintFault equ -474
_LVOReadArgs equ -798
_LVOFreeArgs equ -858
_LVOMatchFirst equ -822
_LVOMatchNext equ -828
_LVOMatchEnd equ -834
_LVOOpen equ -030
_LVOClose equ -036
_LVORead equ -042
_LVOWrite equ -048
_LVODeleteFile equ -072
_LVORename equ -078
_LVOLock equ -084
_LVOUnLock equ -090
_LVOCurrentDir equ -126
_LVOSetComment equ -180
_LVOSetProtection equ -186
_LVOFlush equ -360
_LVOExamineFH equ -390
_LVOCheckSignal equ -792
_LVOFilePart equ -870
_LVOPutStr equ -948
_LVOVPrintf equ -954
MODE_OLDFILE equ 1005
MODE_NEWFILE equ 1006
ACCESS_READ equ -002
fib_DirEntryType equ $004
fib_Protection equ $074
fib_Size equ $07C
fib_Comment equ $090
fib_SIZEOF equ $104
FIBB_ARCHIVE equ $004
SIGBREAKB_CTRL_C equ $00C
SIGBREAKB_CTRL_D equ $00D
SIGBREAKB_CTRL_E equ $00E
SIGBREAKB_CTRL_F equ $00F
************************************************ bss datas ******************
FIBlock rs.b fib_SIZEOF ;buffer for fileinfoblock
DOSBase rs.l 1 ;ptr. base of library
ArgArray rs.l 0 ;argarray
IndexFile rs.l 1 ;ptr. path/name indexfile
OutputFile rs.l 1 ;ptr. path/name outputfile
SortedFile rs.l 1 ;ptr. path/name sorted ifile
SkipHead rs.l 1 ;# of lines to skip
Case rs.l 1 ;flag sort case sensitive
Reverse rs.l 1 ;flag sort reverse
Slow rs.l 1 ;flag (write line by line)
RDArgs rs.l 1 ;returned by readargs
IHandle rs.l 1 ;handle indexfile
OHandle rs.l 1 ;handle outputfile
SHandle rs.l 1 ;handle sorted indexfile
MemoryA rs.l 1 ;membase indexfile
SkipHM rs.l 1 ;membase indexfile w/o head
MemoryB rs.l 1 ;membase sorted indexfile
MSizeB rs.l 1 ;memsize sorted file w/o head
MemoryC rs.l 1 ;membase outputfile
MSizeC rs.l 1 ;memsize outputfile
RCode1 rs.l 1 ;errorcode -> rc
RCode2 rs.l 1 ;errorcode -> result2
Count rs.l 1 ;# of bytes written out/file
SCount rs.l 1 ;# of bytes written sort/file
EList rs.l 1 ;membase entrylist
ELSize rs.l 1 ;size of entrylist
Lines rs.l 1 ;# of lines (ifile w/o head)
BSS_Size rs.b 0 ;bss_size over all
*****************************************************************************
Start movem.l D1-D7/A0-A6,-(SP) ;save registers
ifd BSS_Section ;check assembler condition
movea.l Start-4(pc),A5 ;get bss_section
addq.l #1,A5 ;skip pointer (next segment)
adda.l A5,A5 ;convert bpcl_pointer
adda.l A5,A5 ;to real_address
elseif ;otherwise
lea DataBase(pc),A5 ;set data area
endc ;end condition
************************************************ open required libraries ****
moveq #20,D0 ;failat level
move.l D0,RCode1(A5) ;preset error (no library)
movea.l 4.w,A6 ;set EXEC to call a function
moveq #37,D0 ;required library version
lea DOSName(pc),A1 ;set library name
jsr _LVOOpenLibrary(A6) ;use EXEC to (openlibrary)
move.l D0,DOSBase(A5) ;save base
beq.b CloseLibs ;branch if not open
*****************************************************************************
bsr.b Main
************************************************ close libraries ************
CloseLibs movea.l 4.w,A6 ;set EXEC to call a function
CloseDOS move.l DOSBase(A5),D1 ;get base_ptr
beq.b ExitDOS ;branch when not open
movea.l D1,A1 ;set base_ptr
jsr _LVOCloseLibrary(A6) ;use EXEC to (closelibrary)
ExitDOS move.l RCode1(A5),D0 ;set returncode
movem.l (SP)+,D1-D7/A0-A6 ;restore registers
rts ;go back (shell)
*****************************************************************************
DOSName dc.b "dos.library",0
*****************************************************************************
version dc.b "$VER: ChkIndex 2.0 48 (22.10.03) by joerg riemer jan'03",0
*****************************************************************************
cnop 0,4
*****************************************************************************
Main clr.l RCode1(A5) ;clear returncode
;-----------------------------------------------
bsr ReadArgs ;read user_arguments
bsr ChkArgs ;check "SKIP/N" for wrong #
bsr.b ChkReverse ;sort reverse ?
bsr OpenOFile ;open outputfile
bsr OpenSFile ;open sorted indexfile (new)
bsr GetIFile ;open/read/close indexfile
bsr SkipHeader ;skip headlines
bsr.b ChkBreak ;check for user break
bsr CreateEList ;create entrylist
bsr.b ChkBreak ;check for user break
bsr SortEList ;sort entrylist
bsr.b ChkBreak ;check for user break
bsr WriteSFile ;write/close sorted indexfile
bsr.b ChkBreak ;check for user break
bsr GetMEntries ;search for multiple entries
;-----------------------------------------------
Quit bsr FreeMemC ;free memory (outputfile)
bsr FreeMemB ;free memory (sorted ifile)
bsr FreeEList ;free memory (entrylist)
bsr FreeMemA ;free memory (indexfile)
bsr CloseSFile ;close sorted indexfile
bsr CloseIFile ;close indexfile
bsr CloseOFile ;close outputfile
bsr FreeArgs ;free memory (readargs)
rts ;go back
*****************************************************************************
cnop 0,4
*********************************************** check reverse sort **********
ChkReverse tst.w Reverse(A5) ;sort reverse ?
beq.b .quit ;no, quit
moveq #1,D0 ;get switch
lea SortEList(pc),A0 ;get routine
move.w #Patch1,D1 ;get offset patch 1
eor.b D0,0(A0,D1.w) ;flip condition (bcc<->bcs)
move.w #Patch2,D1 ;get offset patch 2
eor.b D0,0(A0,D1.w) ;flip condition (bcs<->bcc)
lea SortEListC(pc),A0 ;get routine
move.w #Patch3,D1 ;get offset patch 1
eor.b D0,0(A0,D1.w) ;flip condition (bcc<->bcs)
move.w #Patch4,D1 ;get offset patch 2
eor.b D0,0(A0,D1.w) ;flip condition (bcc<->bcs)
movea.l 4.w,A6 ;set EXEC to call a function
jsr _LVOCacheClearU(A6) ;clear cache if available
.quit rts ;go back
*****************************************************************************
cnop 0,4
*********************************************** check for break <ctrl><c> ***
ChkBreak moveq #00,D1 ;prepare signal mask
bset #12,D1 ;set break bit (ctrl_c)
movea.l DOSBase(A5),A6 ;set DOS to call a function
jsr _LVOCheckSignal(A6) ;use DOS to (checksignal)
btst #12,D0 ;test break bit (ctrl_c)
bne Error3 ;if set, branch (set ioerr)
rts ;go back
*****************************************************************************
cnop 0,4
*********************************************** create list of all lines ****
CreateEList movea.l SkipHM(A5),A0 ;base of indexfile w/o head
movea.l A0,A1 ;preset register (size mem_b)
;-----------------------------------------------
moveq #00,D0 ;prepare register
moveq #10,D7 ;set linefeed
.CalcLines cmp.b (A0)+,D7 ;search linefeed
bne.b .CalcLines ;do until
addq.l #1,D0 ;inc. number of lines
tst.b (A0) ;check for eof
bne.b .CalcLines ;do until
;-----------------------------------------------
suba.l A1,A0 ;calc. size of memory_b
move.l A0,MSizeB(A5) ;save size (sorted ifile!)
;-----------------------------------------------
move.l D0,Lines(A5) ;save # of lines
lsl.l #3,D0 ;need 8 bytes for each line!
addq.l #8,D0 ;add size for list_terminator
move.l D0,ELSize(A5) ;save size
moveq #0,D1 ;no memory options
movea.l 4.w,A6 ;set EXEC to call a function
jsr _LVOAllocMem(A6) ;use EXEC to (allocmem)
move.l D0,EList(A5) ;save memorybase
beq Error2 ;branch if fail (close file)
;-----------------------------------------------
test movea.l SkipHM(A5),A0 ;get indexfile
movea.l D0,A1 ;get entrylist
.MakeList move.l A0,D0 ;reset register
move.l A0,(A1)+ ;save base of line (1.long)
.CalcLSize cmp.b (A0)+,D7 ;search for linefeed
bne.b .CalcLSize ;do until
sub.l A0,D0 ;calc. string length
neg.l D0 ;calc. string length
move.l D0,(A1)+ ;save length of line (2.long)
tst.b (A0) ;check for eof
bne.b .MakeList ;do until
moveq #0,D0 ;get terminator
move.l D0,(A1)+ ;set list_terminator
move.l D0,(A1) ;set list_terminator
rts ;go back
******************************************************************************
cnop 0,4
*********************************************** quicksort case insensitive **
SortEList movea.l EList(A5),A0 ;get entrylist
move.l Lines(A5),D1 ;get # of lines
beq .QuitSort ;branch if zero
tst.w Case(A5)
bne SortEListC
lea ChrTab(pc),A6 ;sort case insensitive
moveq #0,D0 ;init. left
subq.l #1,D1 ;init. right
.QuickSort: movem.l D4-7,-(SP)
************************************************
* le = lo; ri = hi *****************************
move.l D0,D4 ;left
move.l D1,D5 ;right
move.l D0,D6 ;low
move.l D1,D7 ;high
************************************************
* p = (hi+lo)/2 ********************************
move.l D1,D3 ;get high
add.l D0,D3 ;(hi+lo)
lsr.l #1,D3 ;(hi+lo)/2
lsl.l #3,D3 ;offset for 2 lwords
move.l 0(A0,D3.l),A3 ;get pivotelement
move.l 4(A0,D3.l),A4 ;get length of pivotelement
subq.l #1,A4 ;dbra!!
moveq #0,D0
moveq #0,D1
bra.b .le_loop_1
************************************************
* while (f[le] < p) ; le++ *********************
.le_loop_2 addq.l #1,D4 ;le++
.le_loop_1 move.l D4,D3 ;get left_index
lsl.l #3,D3 ;prepare offset
movea.l 0(A0,D3.l),A1 ;get entry to compare
movea.l A3,A2 ;set pivotelement
move.l A4,D2 ;set length of pivotelement
.le_compare move.b (A1)+,D0 ;compare entries
move.b (A2)+,D1 ;char. by char.
and.b 0(A6,D0.w),D0 ;force uppercase
and.b 0(A6,D1.w),D1 ;for both
cmp.b D1,D0
dbne d2,.le_compare ;do until end of line
Patch1 equ *-SortEList
bcc.b .ri_loop_1 ;branch if entry > pivot
tst.w d2 ;entry = pivot ?
bpl.b .le_loop_2 ;inc. left_index if not
************************************************
bra.b .ri_loop_1
************************************************
* while ( p < f[ri]); ri-- *********************
.ri_loop_2 subq.l #1,D5 ;ri--
.ri_loop_1 move.l D5,D3 ;get right_index
lsl.l #3,D3 ;prepare offset
movea.l 0(A0,D3.l),A1 ;get entry to compare
movea.l A3,A2 ;set pivotelement
move.l A4,D2 ;set length of pivotelement
.ri_compare move.b (A1)+,D0 ;compare entries
move.b (A2)+,D1 ;char. by char.
and.b 0(A6,D0.w),D0 ;force uppercase
and.b 0(A6,D1.w),D1 ;for both
cmp.b D1,D0
dbne d2,.ri_compare ;do until end of line
Patch2 equ *-SortEList
bcs.b .skip1 ;branch if entry < pivot
tst.w d2 ;entry = pivot ?
bpl.b .ri_loop_2 ;dec. right_index if not
************************************************
* if (le <= ri); swap (f,le,ri); le++; ri-- ****
.skip1 cmp.l D5,D4 ;left<=right ?
bgt.b .skip2 ;
beq.b .skip3 ;
move.l D4,D3 ;left
lsl.l #3,D3
movea.l A0,A1
adda.l D3,A1
move.l D5,D3 ;right
lsl.l #3,D3
movea.l A0,A2
adda.l D3,A2
move.l (A1),D2 ;swap entry pointers
move.l (A2),(A1)+ ;
move.l D2,(A2)+ ;
move.l (A1),D2 ;swap entry_length, too
move.l (A2),(A1) ;
move.l D2,(A2) ;
.skip3 addq.l #1,D4 ;le++
subq.l #1,D5 ;ri--
************************************************
* if le <= ri do again *************************
cmp.l D5,D4 ;right,left
ble.b .le_loop_1
************************************************
* if (lo < ri) quicksort (f,lo,ri) *************
.skip2 cmp.l D5,D6 ;right,low
bge.b .goon_1
move.l D6,D0 ;low
move.l D5,D1 ;right
bsr .QuickSort
************************************************
* if (le < hi) quicksort (f,le,hi) *************
.goon_1 cmp.l D4,D7 ;left,high
ble.b .goon_2
move.l D4,D0 ;left
move.l D7,D1 ;high
bsr .QuickSort
************************************************
.goon_2 movem.l (SP)+,D4-7
.QuitSort rts
*****************************************************************************
cnop 0,4
*****************************************************************************
ChrTab dc.b $FF,$FF,$FF,$FF,$FF,$FF,$FF,$FF,$FF,$FF,$FF,$FF,$FF,$FF,$FF,$FF
dc.b $FF,$FF,$FF,$FF,$FF,$FF,$FF,$FF,$FF,$FF,$FF,$FF,$FF,$FF,$FF,$FF
dc.b $FF,$FF,$FF,$FF,$FF,$FF,$FF,$FF,$FF,$FF,$FF,$FF,$FF,$FF,$FF,$FF
dc.b $FF,$FF,$FF,$FF,$FF,$FF,$FF,$FF,$FF,$FF,$FF,$FF,$FF,$FF,$FF,$FF
dc.b $FF,$FF,$FF,$FF,$FF,$FF,$FF,$FF,$FF,$FF,$FF,$FF,$FF,$FF,$FF,$FF
dc.b $FF,$FF,$FF,$FF,$FF,$FF,$FF,$FF,$FF,$FF,$FF,$FF,$FF,$FF,$FF,$FF
dc.b $FF,$41,$42,$43,$44,$45,$46,$47,$48,$49,$4A,$4B,$4C,$4D,$4E,$4F
dc.b $50,$51,$52,$53,$54,$55,$56,$57,$58,$59,$5A,$FF,$FF,$FF,$FF,$FF
dc.b $FF,$FF,$FF,$FF,$FF,$FF,$FF,$FF,$FF,$FF,$FF,$FF,$FF,$FF,$FF,$FF
dc.b $FF,$FF,$FF,$FF,$FF,$FF,$FF,$FF,$FF,$FF,$FF,$FF,$FF,$FF,$FF,$FF
dc.b $FF,$FF,$FF,$FF,$FF,$FF,$FF,$FF,$FF,$FF,$FF,$FF,$FF,$FF,$FF,$FF
dc.b $FF,$FF,$FF,$FF,$FF,$FF,$FF,$FF,$FF,$FF,$FF,$FF,$FF,$FF,$FF,$FF
dc.b $FF,$FF,$FF,$FF,$FF,$FF,$FF,$FF,$FF,$FF,$FF,$FF,$FF,$FF,$FF,$FF
dc.b $FF,$FF,$FF,$FF,$FF,$FF,$FF,$FF,$FF,$FF,$FF,$FF,$FF,$FF,$FF,$FF
dc.b $FF,$FF,$FF,$FF,$FF,$FF,$FF,$FF,$FF,$FF,$FF,$FF,$FF,$FF,$FF,$FF
dc.b $FF,$FF,$FF,$FF,$FF,$FF,$FF,$FF,$FF,$FF,$FF,$FF,$FF,$FF,$FF,$FF
******************************************************************************
cnop 0,4
*********************************************** quicksort case sensitive ****
SortEListC moveq #0,D0 ;init. left
subq.l #1,D1 ;init. right (f.length-1)
.QuickSort movem.l D4-7,-(SP)
************************************************
* le = lo; ri = hi *****************************
move.l D0,D4 ;left
move.l D1,D5 ;right
move.l D0,D6 ;low
move.l D1,D7 ;high
************************************************
* p = (hi+lo)/2 ********************************
move.l D1,D3 ;get high
add.l D0,D3 ;(hi+lo)
lsr.l #1,D3 ;(hi+lo)/2
lsl.l #3,D3 ;offset for 2 lwords
move.l 0(A0,D3.l),A3 ;get pivotelement
move.l 4(A0,D3.l),A4 ;get length of pivotelement
subq.l #1,A4 ;dbra!!
bra.b .le_loop_1
************************************************
* while (f[le] < p) ; le++ *********************
.le_loop_2 addq.l #1,D4 ;le++
.le_loop_1 move.l D4,D3 ;get left_index
lsl.l #3,D3 ;prepare offset
movea.l 0(A0,D3.l),A1 ;get entry to compare
movea.l A3,A2 ;set pivotelement
move.l A4,D2 ;set length of pivotelement
.le_compare cmp.b (A2)+,(A1)+ ;compare entries
dbne d2,.le_compare ;do until end of line
Patch3 equ *-SortEListC
bcc.b .ri_loop_1 ;branch if entry > pivot
tst.w d2 ;entry = pivot ?
bpl.b .le_loop_2 ;inc. left_index if not
************************************************
bra.b .ri_loop_1
************************************************
* while ( p < f[ri]); ri-- *********************
.ri_loop_2 subq.l #1,D5 ;ri--
.ri_loop_1 move.l D5,D3 ;get right_index
lsl.l #3,D3 ;prepare offset
movea.l 0(A0,D3.l),A1 ;get entry to compare
movea.l A3,A2 ;set pivotelement
move.l A4,D2 ;set length of pivotelement
.ri_compare cmp.b (A2)+,(A1)+ ;compare entries
dbne d2,.ri_compare ;do until end of line
Patch4 equ *-SortEListC
bcs.b .skip1 ;branch if entry < pivot
tst.w d2 ;entry = pivot ?
bpl.b .ri_loop_2 ;dec. right_index if not
************************************************
* if (le <= ri); swap (f,le,ri); le++; ri-- ****
.skip1 cmp.l D5,D4 ;left<=right ?
bgt.b .skip2 ;
beq.b .skip3 ;
move.l D4,D3 ;left
lsl.l #3,D3
movea.l A0,A1
adda.l D3,A1
move.l D5,D3 ;right
lsl.l #3,D3
movea.l A0,A2
adda.l D3,A2
move.l (A1),D2 ;swap entry pointers
move.l (A2),(A1)+
move.l D2,(A2)+
move.l (A1),D2 ;swap entry_length, too
move.l (A2),(A1)
move.l D2,(A2)
.skip3 addq.l #1,D4 ;le++
subq.l #1,D5 ;ri--
************************************************
* if le <= ri do again *************************
cmp.l D5,D4 ;right,left
ble.b .le_loop_1
************************************************
* if (lo < ri) quicksort (f,lo,ri) *************
.skip2 cmp.l D5,D6 ;right,low
bge.b .goon_1
move.l D6,D0 ;low
move.l D5,D1 ;right
bsr .QuickSort
************************************************
* if (le < hi) quicksort (f,le,hi) *************
.goon_1 cmp.l D4,D7 ;left,high
ble.b .goon_2
move.l D4,D0 ;left
move.l D7,D1 ;high
bsr .QuickSort
************************************************
.goon_2 movem.l (SP)+,D4-7
.QuitSort rts
*****************************************************************************
cnop 0,4
*********************************************** open new file (output) ******
OpenOFile move.l OutputFile(A5),D1 ;get filename
beq.b .quit
move.l #MODE_NEWFILE,D2 ;open new file!!
movea.l DOSBase(A5),A6 ;set dos_base
jsr _LVOOpen(A6) ;use dos to open file
move.l D0,OHandle(A5) ;save handle
beq Error2 ;print error when fail
.quit rts ;go back
*****************************************************************************
cnop 0,4
*********************************************** search for multiple entries *
GetMEntries tst.l OHandle(A5) ;save equal entries?
beq QuitSearch ;quit if not set
moveq #0,D0 ;char. entry_a
moveq #0,D1 ;char. entry_b
moveq #0,D3 ;length entry_a
moveq #0,D5 ;length entry_b
moveq #0,D7 ;size outputfile
lea ChrTab(pc),A6 ;force uppercase
moveq #1,D6 ;id search_1
bsr Search_1 ;filename,path
addq.b #1,D6 ;id search_2
bsr Search_2 ;filename,size,age,description
addq.b #1,D6 ;id search_3
bsr Search_3 ;filename,size,age
addq.b #1,D6 ;id search_4
bsr Search_4 ;filename,size,description
addq.b #1,D6 ;id search_5
bsr Search_5 ;filename,size
addq.b #1,D6 ;id search_6
bsr Search_6 ;filename,age,description
addq.b #1,D6 ;id search_7
bsr Search_7 ;filename,age
addq.b #1,D6 ;id search_8
bsr Search_8 ;filename,description
addq.b #1,D6 ;id search_9
bsr Search_9 ;filename
*********************************************** save entries quick **********
tst.w Slow(A5)
bne WriteMELBL
;-----------------------------------------------
moveq #8,D0 ;loopcounter
lea StrTab(pc),A0 ;get stringtable
.AddStrSize move.l D0,D1 ;calc. offset
lsl.w #3,D1 ;2 lwords
add.l 4(A0,D1.w),D7 ;add stringlength (1-9)
dbra d0,.AddStrSize ;do for all strings
;-----------------------------------------------
move.l D7,MSizeC(A5) ;save size
move.l D7,D0 ;set size
moveq #0,D1 ;no memory options
movea.l 4.w,A6 ;set EXEC to call a function
jsr _LVOAllocMem(A6) ;use EXEC to (allocmem)
move.l D0,MemoryC(A5) ;save memorybase
beq WriteMELBL ;if fail, save line by line
;-----------------------------------------------
move.l D0,A3 ;presave destination base
moveq #0,D6 ;search id
.DoAgain movea.l A3,A1 ;set destination
move.l D6,D0 ;cal. index
lsl.w #3,D0 ;2 lwords
lea StrTab(pc),A0 ;get stringtable
move.l 0(A0,D0.w),D1 ;get offset_x
move.l 4(A0,D0.w),D0 ;get stringsize_x
add.l D0,A3 ;inc. destination
add.l D1,A0 ;get base string_x
bsr.b CopyMemQ
addq.l #1,D6 ;prepare id
move.l EList(A5),A2 ;get entrylist
subq.l #8,A2 ;simple avoids bra!
.IncListA addq.l #8,A2 ;inc. list_a
tst.l (A2) ;check for eol
beq.b .skip ;branch if so
.ChkID cmp.w 4(A2),D6 ;entry marked?
bne.b .IncListA ;branch if not
move.l (A2),A0 ;base of entry (source)
movea.l A3,A1 ;set destination
move.w 6(A2),D0 ;get entrysize
ext.l D0 ;clear highword
add.l D0,A3 ;inc. destination
bsr.b CopyMemQ
addq.l #8,A2 ;inc. list_a
tst.l (A2) ;check for end of list
bne.b .ChkID ;continue if not
.skip cmp.b #9,D6
bne.b .DoAgain
;-----------------------------------------------
move.l OHandle(A5),D1 ;set file
move.l MemoryC(A5),D2 ;set buffer
move.l MSizeC(A5),D3 ;set size
movea.l DOSBase(A5),A6 ;set DOS to call a function
jsr _LVOWrite(A6) ;write file
tst.l D0 ;error returned ?
bmi Error2 ;branch if so
add.l D0,Count(A5) ;inc. byte count
bsr CloseOFile
;-----------------------------------------------
FreeMemC move.l MSizeC(A5),D0 ;get size memory_b
beq.b .quit
move.l MemoryC(A5),A1 ;get base memory_b
movea.l 4.w,A6 ;set EXEC to call a function
jsr _LVOFreeMem(A6) ;use EXEC to (freemem)
moveq #0,D0
move.l D0,MSizeC(A5) ;clear buffer
move.l D0,MemoryC(A5) ;clear buffer
.quit rts
*****************************************************************************
cnop 0,4
*****************************************************************************
* CopyMemQuicker 2.8 - (C) 1991-1994 Arthur Hagen *
* Parts of code: (C) 1985-1991 Commodore Business Machines Ltd. *
* Posted to the Public Domain *
*****************************************************************************
* cm000.asm start
CopyMemQ moveq #12,d1
cmp.l d1,d0
bcs.s tinycpy ; too small to gain anything
move.w a0,d1
lsr.b #1,d1 ; fastest test for evenness
bcc.s evena0
move.b (a0)+,(a1)+
subq.l #1,d0
evena0 move.w a1,d1
lsr.b #1,d1
bcc.s evenquicker
moveq #36*3,d1
cmp.l d1,d0
bcs.s tinycpy
* This is tricky! They said it couldn't be done...
unevcpy movem.l a2-a4/d2-d7,-(sp)
moveq #32,d1 ; 8 registers of 4 bytes
move.w d1,a3
moveq #34,d1 ; as above plus 2 "roundoff" bytes
move.w d1,a4
sub.l d1,d0
move.l d0,a2
uloop movem.l (a0)+,d0-d7
rol.l #8,d0
rol.l #8,d1
rol.l #8,d2
rol.l #8,d3
rol.l #8,d4
rol.l #8,d5
rol.l #8,d6
rol.l #8,d7
move.b d0,(a1)+
move.b d1,d0
move.b d2,d1
move.b d3,d2
move.b d4,d3
move.b d5,d4
move.b d6,d5
move.b d7,d6
move.b (a0)+,d7
movem.l d0-d7,(a1)
adda.w a3,a1
move.b (a0)+,(a1)+
suba.w a4,a2
move.l a2,d0
bpl.s uloop
add.w a4,d0
movem.l (sp)+,a2-a4/d2-d7
subq.b #1,d0
bcs.s tdone
tloop move.b (a0)+,(a1)+
tinycpy dbf d0,tloop
tdone rts
evenquicker moveq #44*2,d1
cmp.l d1,d0
bcs.s smlmov
moveq #44,d1 ; 11 registers of 4 bytes
sub.l d1,d0
movem.l d2-d7/a2-a6,-(sp)
bigmov movem.l (a0)+,d2-d7/a2-a6
movem.l d2-d7/a2-a6,(a1)
adda.w d1,a1
sub.l d1,d0
bcc.s bigmov
add.w d1,d0
movem.l (sp)+,d2-d7/a2-a6
smlmov lsr.w #1,d0
beq.s even01
bcs.s sm13
lsr.w #1,d0
beq.s even2
bcs.s sm2
sm0 subq.w #1,d0
loop0 move.l (a0)+,(a1)+
dbf d0,loop0
even0 rts
sm2 subq.w #1,d0
loop2 move.l (a0)+,(a1)+
dbf d0,loop2
even2 move.w (a0),(a1)
rts
sm13 lsr.w #1,d0
beq.s even3
bcs.s sm3
sm1 subq.w #1,d0
loop1 move.l (a0)+,(a1)+
dbf d0,loop1
even1 move.b (a0),(a1)
rts
sm3 subq.w #1,d0
loop3 move.l (a0)+,(a1)+
dbf d0,loop3
even3 move.w (a0)+,(a1)+
move.b (a0),(a1)
rts
even01 bcs.s even1
rts
* cm000.asm end
*****************************************************************************
cnop 0,4
************************************************ save entries line by line **
WriteMELBL moveq #0,D6 ;search id
move.l OHandle(A5),D7 ;get filehandle
movea.l DOSBase(A5),A6 ;get dosbase
.DoAgain move.l D6,D0 ;cal. index
lsl.w #3,D0 ;2 lwords
lea StrTab(pc),A0 ;get stringtable
move.l 4(A0,D0.w),D3 ;set (size)
add.l 0(A0,D0.w),A0 ;get string
move.l A0,D2 ;set (buffer)
move.l D7,D1 ;set (file)
jsr _LVOWrite(A6) ;use DOS to (write) bytes
tst.l D0 ;error returned ?
bmi Error2 ;branch if so
add.l D0,Count(A5) ;inc. byte count
addq.l #1,D6 ;prepare id
move.l EList(A5),A2 ;get entrylist
subq.l #8,A2 ;simple avoids bra!
.IncListA addq.l #8,A2 ;inc. list_a
tst.l (A2) ;check for eol
beq.b .skip ;branch if so
.ChkID cmp.w 4(A2),D6 ;entry marked?
bne.b .IncListA ;branch if not
move.l (A2),D2 ;set (buffer)
move.w 6(A2),D3 ;set (size)
ext.l D3 ;clear highword
move.l D7,D1 ;set (file)
jsr _LVOWrite(A6) ;use DOS to (write) bytes
tst.l D0 ;error returned ?
bmi Error2 ;branch if so
add.l D0,Count(A5) ;inc. byte count
addq.l #8,A2 ;inc. list_a
tst.l (A2) ;check for end of list
bne.b .ChkID ;continue if not
.skip cmp.b #9,D6
bne.b .DoAgain
*********************************************** close outputfile ************
CloseOFile move.l OHandle(A5),D1 ;set filehandle
beq.b .quit ;branch if not set!
movea.l DOSBase(A5),A6 ;set DOS to call a function
jsr _LVOClose(A6) ;use DOS to (close) file
moveq #0,D0 ;clear filehandle
move.l D0,OHandle(A5)
tst.l Count(A5) ;some bytes written ?
bne.b .quit ;branch if so
move.l OutputFile(A5),D1 ;set filename
jsr _LVODeleteFile(A6) ;use dos to (delete) file
.quit rts ;go back
*********************************************** search for equal entries ****
* search FILENAME
Search_9 movea.l EList(A5),A2 ;entrylist
subq.l #8,A2 ;simple avoids bra!
.IncListA addq.l #8,A2 ;inc. list_a
tst.w 4(A2) ;test for skip_over
bne.b .IncListA ;branch if so
move.w 6(A2),D3 ;get length_a / check for eol
beq QuitSearch ;branch if so
moveq #0,D4 ;clr flag (print sourceline)
movea.l A2,A3 ;set list_b
.IncListB addq.l #8,A3 ;inc. list_b
tst.w 4(A3) ;test for skip_over
bne.b .IncListB ;branch if so
move.w 6(A3),D5 ;get length_b / check for eol
beq QuitSearch ;branch if so
;-----------------------------------------------
moveq #18,D2 ;loopcounter
movea.l (A2),A0 ;get filename_field entry (a)
movea.l (A3),A1 ;get filename_field entry (b)
.Compare_1 move.b (A0)+,D0 ;compare filenames
move.b (A1)+,D1 ;char. by char.
and.b 0(A6,D0.w),D0 ;force uppercase
and.b 0(A6,D1.w),D1 ;for both
cmp.b D0,D1 ;compare chars.
dbne D2,.Compare_1 ;do loop as long as equal
;and counter is positive
tst.w D2 ;found same filenames ?
bpl.b .IncListA ;branch if not
pea .IncListB(pc) ;set return_address
bra MarkEntries ;mark entries
*****************************************************************************
cnop 0,4
*****************************************************************************
* search FILENAME, DESCRIPTION
Search_8 movea.l EList(A5),A2 ;entrylist
subq.l #8,A2 ;simple avoids bra!
.IncListA addq.l #8,A2 ;inc. list_a
tst.w 4(A2) ;test for skip_over
bne.b .IncListA ;branch if so
move.w 6(A2),D3 ;get length_a / check for eol
beq QuitSearch ;branch if so
moveq #0,D4 ;clr flag (print sourceline)
movea.l A2,A3 ;set list_b
.IncListB addq.l #8,A3 ;inc. list_b
tst.w 4(A3) ;test for skip_over
bne.b .IncListB ;branch if so
move.w 6(A3),D5 ;get length_b / check for eol
beq QuitSearch ;branch if so
;-----------------------------------------------
moveq #18,D2 ;loopcounter
movea.l (A2),A0 ;get filename_field entry (a)
movea.l (A3),A1 ;get filename_field entry (b)
.Compare_1 move.b (A0)+,D0 ;compare filenames
move.b (A1)+,D1 ;char. by char.
and.b 0(A6,D0.w),D0 ;force uppercase
and.b 0(A6,D1.w),D1 ;for both
cmp.b D0,D1 ;compare chars.
dbne D2,.Compare_1 ;do loop as long as equal
;and counter is positive
tst.w D2 ;found same filenames ?
bpl.b .IncListA ;branch if not
;-----------------------------------------------
moveq #-39,D2 ;loopcounter
add.w D3,D2 ;calc. length of description
lea 19(A0),A0 ;get description_field (a)
lea 19(A1),A1 ;get description_field (b)
.Compare_4 move.b (A0)+,D0 ;compare file_descriptions
move.b (A1)+,D1 ;char. by char.
and.b 0(A6,D0.w),D0 ;force uppercase
and.b 0(A6,D1.w),D1 ;for both
cmp.b D0,D1 ;compare chars.
dbne D2,.Compare_4 ;do loop as long as equal
;and counter is positive
tst.w D2 ;found same description ?
bpl.b .IncListB ;branch if not
pea .IncListB(pc) ;set return_address
bra MarkEntries ;mark entries
*****************************************************************************
cnop 0,4
*****************************************************************************
* search FILENAME, AGE
Search_7 movea.l EList(A5),A2 ;entrylist
subq.l #8,A2 ;simple avoids bra!
.IncListA addq.l #8,A2 ;inc. list_a
tst.w 4(A2) ;test for skip_over
bne.b .IncListA ;branch if so
move.w 6(A2),D3 ;get length_a / check for eol
beq QuitSearch ;branch if so
moveq #0,D4 ;clr flag (print sourceline)
movea.l A2,A3 ;set list_b
.IncListB addq.l #8,A3 ;inc. list_b
tst.w 4(A3) ;test for skip_over
bne.b .IncListB ;branch if so
move.w 6(A3),D5 ;get length_b / check for eol
beq QuitSearch ;branch if so
;-----------------------------------------------
moveq #18,D2 ;loopcounter
movea.l (A2),A0 ;get filename_field entry (a)
movea.l (A3),A1 ;get filename_field entry (b)
.Compare_1 move.b (A0)+,D0 ;compare filenames
move.b (A1)+,D1 ;char. by char.
and.b 0(A6,D0.w),D0 ;force uppercase
and.b 0(A6,D1.w),D1 ;for both
cmp.b D0,D1 ;compare chars.
dbne D2,.Compare_1 ;do loop as long as equal
;and counter is positive
tst.w D2 ;found same filenames ?
bpl.b .IncListA ;branch if not
;-----------------------------------------------
moveq #2,D2 ;loopcounter
lea 16(A0),A0 ;get age_field entry (a)
lea 16(A1),A1 ;get age_field entry (b)
.Compare_3 move.b (A0)+,D0 ;compare filesizes
move.b (A1)+,D1 ;char. by char.
and.b 0(A6,D0.w),D0 ;force uppercase
and.b 0(A6,D1.w),D1 ;for both
cmp.b D0,D1 ;compare chars.
dbne D2,.Compare_3 ;do loop as long as equal
;and counter is positive
tst.w D2 ;found equal filesize ?
bpl.b .IncListB ;branch if not
pea .IncListB(pc) ;set return_address
bra MarkEntries ;mark entries
*****************************************************************************
cnop 0,4
*****************************************************************************
* search FILENAME, AGE, DESCRIPTION
Search_6 movea.l EList(A5),A2 ;entrylist
subq.l #8,A2 ;simple avoids bra!
.IncListA addq.l #8,A2 ;inc. list_a
tst.w 4(A2) ;test for skip_over
bne.b .IncListA ;branch if so
move.w 6(A2),D3 ;get length_a / check for eol
beq QuitSearch ;branch if so
moveq #0,D4 ;clr flag (print sourceline)
movea.l A2,A3 ;set list_b
.IncListB addq.l #8,A3 ;inc. list_b
tst.w 4(A3) ;test for skip_over
bne.b .IncListB ;branch if so
move.w 6(A3),D5 ;get length_b / check for eol
beq QuitSearch ;branch if so
;-----------------------------------------------
moveq #18,D2 ;loopcounter
movea.l (A2),A0 ;get filename_field entry (a)
movea.l (A3),A1 ;get filename_field entry (b)
.Compare_1 move.b (A0)+,D0 ;compare filenames
move.b (A1)+,D1 ;char. by char.
and.b 0(A6,D0.w),D0 ;force uppercase
and.b 0(A6,D1.w),D1 ;for both
cmp.b D0,D1 ;compare chars.
dbne D2,.Compare_1 ;do loop as long as equal
;and counter is positive
tst.w D2 ;found same filenames ?
bpl.b .IncListA ;branch if not
;-----------------------------------------------
moveq #2,D2 ;loopcounter
lea 16(A0),A0 ;get age_field entry (a)
lea 16(A1),A1 ;get age_field entry (b)
.Compare_3 move.b (A0)+,D0 ;compare filesizes
move.b (A1)+,D1 ;char. by char.
and.b 0(A6,D0.w),D0 ;force uppercase
and.b 0(A6,D1.w),D1 ;for both
cmp.b D0,D1 ;compare chars.
dbne D2,.Compare_3 ;do loop as long as equal
;and counter is positive
tst.w D2 ;found equal filesize ?
bpl.b .IncListB ;branch if not
;-----------------------------------------------
moveq #-39,D2 ;loopcounter
add.w D3,D2 ;calc. length of description
.Compare_4 move.b (A0)+,D0 ;compare file_descriptions
move.b (A1)+,D1 ;char. by char.
and.b 0(A6,D0.w),D0 ;force uppercase
and.b 0(A6,D1.w),D1 ;for both
cmp.b D0,D1 ;compare chars.
dbne D2,.Compare_4 ;do loop as long as equal
;and counter is positive
tst.w D2 ;found same description ?
bpl.b .IncListB ;branch if not
pea .IncListB(pc) ;set return_address
bra MarkEntries ;mark entries
*****************************************************************************
cnop 0,4
*****************************************************************************
* search FILENAME, SIZE
Search_5 movea.l EList(A5),A2 ;entrylist
subq.l #8,A2 ;simple avoids bra!
.IncListA addq.l #8,A2 ;inc. list_a
tst.w 4(A2) ;test for skip_over
bne.b .IncListA ;branch if so
move.w 6(A2),D3 ;get length_a / check for eol
beq QuitSearch ;branch if so
moveq #0,D4 ;clr flag (print sourceline)
movea.l A2,A3 ;set list_b
.IncListB addq.l #8,A3 ;inc. list_b
tst.w 4(A3) ;test for skip_over
bne.b .IncListB ;branch if so
move.w 6(A3),D5 ;get length_b / check for eol
beq QuitSearch ;branch if so
;-----------------------------------------------
moveq #18,D2 ;loopcounter
movea.l (A2),A0 ;get filename_field entry (a)
movea.l (A3),A1 ;get filename_field entry (b)
.Compare_1 move.b (A0)+,D0 ;compare filenames
move.b (A1)+,D1 ;char. by char.
and.b 0(A6,D0.w),D0 ;force uppercase
and.b 0(A6,D1.w),D1 ;for both
cmp.b D0,D1 ;compare chars.
dbne D2,.Compare_1 ;do loop as long as equal
;and counter is positive
tst.w D2 ;found same filenames ?
bpl.b .IncListA ;branch if not
;-----------------------------------------------
moveq #4,D2 ;loopcounter
lea 11(A0),A0 ;get size_field entry (a)
lea 11(A1),A1 ;get size_field entry (b)
.Compare_2 move.b (A0)+,D0 ;compare filesizes
move.b (A1)+,D1 ;char. by char.
and.b 0(A6,D0.w),D0 ;force uppercase
and.b 0(A6,D1.w),D1 ;for both
cmp.b D0,D1 ;compare chars.
dbne D2,.Compare_2 ;do loop as long as equal
;and counter is positive
tst.w D2 ;found equal filesize ?
bpl.b .IncListB ;branch if not
pea .IncListB(pc) ;set return_address
bra MarkEntries ;mark entries
*****************************************************************************
cnop 0,4
*****************************************************************************
* search FILENAME, SIZE, DESCRIPTION
Search_4 movea.l EList(A5),A2 ;entrylist
subq.l #8,A2 ;simple avoids bra!
.IncListA addq.l #8,A2 ;inc. list_a
tst.w 4(A2) ;test for skip_over
bne.b .IncListA ;branch if so
move.w 6(A2),D3 ;get length_a / check for eol
beq QuitSearch ;branch if so
moveq #0,D4 ;clr flag (print sourceline)
movea.l A2,A3 ;set list_b
.IncListB addq.l #8,A3 ;inc. list_b
tst.w 4(A3) ;test for skip_over
bne.b .IncListB ;branch if so
move.w 6(A3),D5 ;get length_b / check for eol
beq QuitSearch ;branch if so
;-----------------------------------------------
moveq #18,D2 ;loopcounter
movea.l (A2),A0 ;get filename_field entry (a)
movea.l (A3),A1 ;get filename_field entry (b)
.Compare_1 move.b (A0)+,D0 ;compare filenames
move.b (A1)+,D1 ;char. by char.
and.b 0(A6,D0.w),D0 ;force uppercase
and.b 0(A6,D1.w),D1 ;for both
cmp.b D0,D1 ;compare chars.
dbne D2,.Compare_1 ;do loop as long as equal
;and counter is positive
tst.w D2 ;found same filenames ?
bpl.b .IncListA ;branch if not
;-----------------------------------------------
moveq #4,D2 ;loopcounter
lea 11(A0),A0 ;get size_field entry (a)
lea 11(A1),A1 ;get size_field entry (b)
.Compare_2 move.b (A0)+,D0 ;compare filesizes
move.b (A1)+,D1 ;char. by char.
and.b 0(A6,D0.w),D0 ;force uppercase
and.b 0(A6,D1.w),D1 ;for both
cmp.b D0,D1 ;compare chars.
dbne D2,.Compare_2 ;do loop as long as equal
;and counter is positive
tst.w D2 ;found equal filesize ?
bpl.b .IncListB ;branch if not
;-----------------------------------------------
moveq #-39,D2 ;loopcounter
add.w D3,D2 ;calc. length of description
addq #3,A0 ;get description_field (a)
addq #3,A1 ;get description_field (b)
.Compare_4 move.b (A0)+,D0 ;compare file_descriptions
move.b (A1)+,D1 ;char. by char.
and.b 0(A6,D0.w),D0 ;force uppercase
and.b 0(A6,D1.w),D1 ;for both
cmp.b D0,D1 ;compare chars.
dbne D2,.Compare_4 ;do loop as long as equal
;and counter is positive
tst.w D2 ;found same description ?
bpl.b .IncListB ;branch if not
pea .IncListB(pc) ;set return_address
bra MarkEntries ;mark entries
*****************************************************************************
cnop 0,4
*****************************************************************************
* search FILENAME, SIZE, AGE
Search_3 movea.l EList(A5),A2 ;entrylist
subq.l #8,A2 ;simple avoids bra!
.IncListA addq.l #8,A2 ;inc. list_a
tst.w 4(A2) ;test for skip_over
bne.b .IncListA ;branch if so
move.w 6(A2),D3 ;get length_a / check for eol
beq QuitSearch ;branch if so
moveq #0,D4 ;clr flag (print sourceline)
movea.l A2,A3 ;set list_b
.IncListB addq.l #8,A3 ;inc. list_b
tst.w 4(A3) ;test for skip_over
bne.b .IncListB ;branch if so
move.w 6(A3),D5 ;get length_b / check for eol
beq QuitSearch ;branch if so
;-----------------------------------------------
moveq #18,D2 ;loopcounter
movea.l (A2),A0 ;get filename_field entry (a)
movea.l (A3),A1 ;get filename_field entry (b)
.Compare_1 move.b (A0)+,D0 ;compare filenames
move.b (A1)+,D1 ;char. by char.
and.b 0(A6,D0.w),D0 ;force uppercase
and.b 0(A6,D1.w),D1 ;for both
cmp.b D0,D1 ;compare chars.
dbne D2,.Compare_1 ;do loop as long as equal
;and counter is positive
tst.w D2 ;found same filenames ?
bpl.b .IncListA ;branch if not
;-----------------------------------------------
moveq #4,D2 ;loopcounter
lea 11(A0),A0 ;get size_field entry (a)
lea 11(A1),A1 ;get size_field entry (b)
.Compare_2 move.b (A0)+,D0 ;compare filesizes
move.b (A1)+,D1 ;char. by char.
and.b 0(A6,D0.w),D0 ;force uppercase
and.b 0(A6,D1.w),D1 ;for both
cmp.b D0,D1 ;compare chars.
dbne D2,.Compare_2 ;do loop as long as equal
;and counter is positive
tst.w D2 ;found equal filesize ?
bpl.b .IncListB ;branch if not
;-----------------------------------------------
moveq #2,D2 ;loopcounter
.Compare_3 move.b (A0)+,D0 ;compare fileages
move.b (A1)+,D1 ;char. by char.
and.b 0(A6,D0.w),D0 ;force uppercase
and.b 0(A6,D1.w),D1 ;for both
cmp.b D0,D1 ;compare chars.
dbne D2,.Compare_3 ;do loop as long as equal
;and counter is positive
tst.w D2 ;found equal filesize ?
bpl.b .IncListB ;branch if not
pea .IncListB(pc) ;set return_address
bra MarkEntries ;mark entries
*****************************************************************************
cnop 0,4
*****************************************************************************
* search FILENAME, SIZE, AGE, DESCRIPTION
Search_2 movea.l EList(A5),A2 ;entrylist
subq.l #8,A2 ;simple avoids bra!
.IncListA addq.l #8,A2 ;inc. list_a
tst.w 4(A2) ;test for skip_over
bne.b .IncListA ;branch if so
move.w 6(A2),D3 ;get length / check for eol
beq QuitSearch ;branch if so
moveq #0,D4 ;clr flag (print sourceline)
movea.l A2,A3 ;set list_b
.IncListB addq.l #8,A3 ;inc. list_b
tst.w 4(A3) ;test for skip_over
bne.b .IncListB ;branch if so
move.w 6(A3),D5 ;get length_b / check for eol
beq QuitSearch ;branch if so
;-----------------------------------------------
moveq #18,D2 ;loopcounter
movea.l (A2),A0 ;get filename_field entry (a)
movea.l (A3),A1 ;get filename_field entry (b)
.Compare_1 move.b (A0)+,D0 ;compare filenames
move.b (A1)+,D1 ;char. by char.
and.b 0(A6,D0.w),D0 ;force uppercase
and.b 0(A6,D1.w),D1 ;for both
cmp.b D0,D1 ;compare chars.
dbne D2,.Compare_1 ;do loop as long as equal
;and counter is positive
tst.w D2 ;found same filenames ?
bpl.b .IncListA ;branch if not
;-----------------------------------------------
moveq #4,D2 ;loopcounter
lea 11(A0),A0 ;get size_field entry (a)
lea 11(A1),A1 ;get size_field entry (b)
.Compare_2 move.b (A0)+,D0 ;compare filesizes
move.b (A1)+,D1 ;char. by char.
and.b 0(A6,D0.w),D0 ;force uppercase
and.b 0(A6,D1.w),D1 ;for both
cmp.b D0,D1 ;compare chars.
dbne D2,.Compare_2 ;do loop as long as equal
;and counter is positive
tst.w D2 ;found equal filesize ?
bpl.b .IncListB ;branch if not
;-----------------------------------------------
moveq #2,D2 ;loopcounter
.Compare_3 move.b (A0)+,D0 ;compare fileages
move.b (A1)+,D1 ;char. by char.
and.b 0(A6,D0.w),D0 ;force uppercase
and.b 0(A6,D1.w),D1 ;for both
cmp.b D0,D1 ;compare chars.
dbne D2,.Compare_3 ;do loop as long as equal
;and counter is positive
tst.w D2 ;found equal filesize ?
bpl.b .IncListB ;branch if not
;-----------------------------------------------
moveq #-39,D2 ;loopcounter
add.w D3,D2 ;calc. length of description
.Compare_4 move.b (A0)+,D0 ;compare file_descriptions
move.b (A1)+,D1 ;char. by char.
and.b 0(A6,D0.w),D0 ;force uppercase
and.b 0(A6,D1.w),D1 ;for both
cmp.b D0,D1 ;compare chars.
dbne D2,.Compare_4 ;do loop as long as equal
;and counter is positive
tst.w D2 ;found same description ?
bpl.b .IncListB ;branch if not
pea .IncListB(pc) ;set return_address
bra.b MarkEntries ;mark entries
*****************************************************************************
cnop 0,4
*****************************************************************************
* search FILENAME, PATH
Search_1 movea.l EList(A5),A2 ;entrylist
subq.l #8,A2 ;simple avoids bra!
.IncListA addq.l #8,A2 ;inc. list_a
tst.w 4(A2) ;test for skip_over
bne.b .IncListA ;branch if so
move.w 6(A2),D3 ;get length_a / check for eol
beq.b QuitSearch ;branch if so
moveq #0,D4 ;clr flag (print sourceline)
movea.l A2,A3 ;set list_b
.IncListB addq.l #8,A3 ;inc. list_b
tst.w 4(A3) ;test for skip_over
bne.b .IncListB ;branch if so
move.w 6(A3),D5 ;get length_b / check for eol
beq.b QuitSearch ;branch if so
;-----------------------------------------------
moveq #29,D2 ;loopcounter
movea.l (A2),A0 ;get filename_field entry (a)
movea.l (A3),A1 ;get filename_field entry (b)
.Compare_1 move.b (A0)+,D0 ;compare filenames
move.b (A1)+,D1 ;char. by char.
and.b 0(A6,D0.w),D0 ;force uppercase
and.b 0(A6,D1.w),D1 ;for both
cmp.b D0,D1 ;compare chars.
dbne D2,.Compare_1 ;do loop as long as equal
;and counter is positive
tst.w D2 ;found same filenames ?
bpl.b .IncListA ;branch if not
pea .IncListB(pc) ;set return_address
*****************************************************************************
MarkEntries tst.b D4 ;mark entry (a) ?
bne.b .MarkEntry_b ;no, entry (b) only!
moveq #1,D4 ;flag, entry (a) marked!
.MarkEntry_a add.l D3,D7 ;inc. me_memory size
move.w D6,4(A2) ;set flag (skip_over)
.MarkEntry_b add.l D5,D7 ;inc. me_memory size
move.w D6,4(A3) ;set flag (skip_over)
QuitSearch rts ;quit search (equal)
*****************************************************************************
cnop 0,4
*****************************************************************************
StrTab dc.l String1-StrTab,S1Size
dc.l String2-StrTab,S2Size
dc.l String3-StrTab,S3Size
dc.l String4-StrTab,S4Size
dc.l String5-StrTab,S5Size
dc.l String6-StrTab,S6Size
dc.l String7-StrTab,S7Size
dc.l String8-StrTab,S8Size
dc.l String9-StrTab,S9Size
*****************************************************************************
String1 dc.b $A," ** entries - including same FILENAME; PATH",$A,$A
S1Size equ *-String1
even
String2 dc.b $A," ** entries - including same FILENAME; SIZE; AGE; DESCRIPTION",$A,$A
S2Size equ *-String2
even
String3 dc.b $A," ** entries - including same FILENAME; SIZE; AGE",$A,$A
S3Size equ *-String3
even
String4 dc.b $A," ** entries - including same FILENAME; SIZE; DESCRIPTION",$A,$A
S4Size equ *-String4
even
String5 dc.b $A," ** entries - including same FILENAME; SIZE",$A,$A
S5Size equ *-String5
even
String6 dc.b $A," ** entries - including same FILENAME; AGE; DESCRIPTION",$A,$A
S6Size equ *-String6
even
String7 dc.b $A," ** entries - including same FILENAME; AGE",$A,$A
S7Size equ *-String7
even
String8 dc.b $A," ** entries - including same FILENAME; DESCRIPTION",$A,$A
S8Size equ *-String8
even
String9 dc.b $A," ** entries - including same FILENAME",$A,$A
S9Size equ *-String9
even
*****************************************************************************
cnop 0,4
*********************************************** skip headlines **************
SkipHeader movea.l MemoryA(A5),A0 ;get base of file
move.l SkipHead(A5),D1 ;skip some lines?
beq.b .quit ;no, quit
movea.l D1,A1 ;get buffer 'skiphead value'
move.l (A1),D0 ;set count
beq.b .quit ;branch if zero
moveq #0,D1
move.b #219,D1 ;preset "seek error..."
moveq #10,D2 ;linefeed
.search cmp.b (A0)+,D2 ;search linefeed
bne.b .search ;do until
tst.b (A0) ;check for eof
beq Error1 ;branch if so!
subq.l #1,D0 ;dec. counter
bne.b .search ;do until zero
.quit move.l A0,SkipHM(A5) ;set new base of file
rts ;go back
*****************************************************************************
cnop 0,4
*********************************************** open new file (sorted) ******
OpenSFile move.l SortedFile(A5),D1 ;get filename
beq.b .quit ;branch if not given
move.l #MODE_NEWFILE,D2 ;open new file
movea.l DOSBase(A5),A6 ;set dos_base
jsr _LVOOpen(A6) ;use dos to open file
move.l D0,SHandle(A5) ;save handle
beq Error2 ;branch if fail
.quit rts ;go back
*****************************************************************************
cnop 0,4
*********************************************** save new file quick *********
WriteSFile move.l SHandle(A5),D7 ;get filehandle
beq QuitSFile ;quit if not set
;-----------------------------------------------
tst.w Slow(A5)
bne.b WriteSFLBL
;-----------------------------------------------
move.l MSizeB(A5),D0 ;get size
moveq #0,D1 ;no memory options
movea.l 4.w,A6 ;set EXEC to call a function
jsr _LVOAllocMem(A6) ;use EXEC to (allocmem)
move.l D0,MemoryB(A5) ;save memorybase
beq.b WriteSFLBL ;if fail, save line by line
;-----------------------------------------------
move.l D0,A3 ;set memorybase
move.l EList(A5),A2 ;get entrylist
move.l (A2)+,A0 ;base of entry
move.l (A2),D0 ;set size
.copymem move.l A3,A1 ;set destination
bsr CopyMemQ
add.l (A2)+,A3 ;inc. destination
move.l (A2)+,A0 ;set next entry
move.l (A2),D0 ;set size, too
bne.b .copymem ;do until eol
;-----------------------------------------------
move.l D7,D1 ;set file
move.l MemoryB(A5),D2 ;set buffer
move.l MSizeB(A5),D3 ;set size
movea.l DOSBase(A5),A6 ;set DOS to call a function
jsr _LVOWrite(A6) ;write file (line by line)
tst.l D0 ;error returned ?
bmi Error2 ;branch if so
add.l D0,SCount(A5) ;inc. byte count
bsr.b CloseSFile
;-----------------------------------------------
FreeMemB move.l MSizeB(A5),D0 ;get size memory_b
beq.b .quit
move.l MemoryB(A5),A1 ;get base memory_b
movea.l 4.w,A6 ;set EXEC to call a function
jsr _LVOFreeMem(A6) ;use EXEC to (freemem)
moveq #0,D0 ;clear register
move.l D0,MSizeB(A5) ;clear buffer
move.l D0,MemoryB(A5) ;clear buffer
.quit rts ;go back
*****************************************************************************
cnop 0,4
*********************************************** save new file line by line **
WriteSFLBL move.l Lines(A5),D6 ;get # of lines
movea.l EList(A5),A2 ;get entrylist
movea.l DOSBase(A5),A6 ;set DOS to call a function
.WriteLine move.l D7,D1 ;set file
move.l (A2)+,D2 ;set buffer
move.l (A2)+,D3 ;set size
jsr _LVOWrite(A6) ;write file (line by line)
tst.l D0 ;error returned ?
bmi Error2 ;branch if so
add.l D0,SCount(A5) ;inc. byte count
subq.l #1,D6 ;dec. line count
bne.b .WriteLine ;do for all lines
*********************************************** close new file (sorted) *****
CloseSFile move.l SHandle(A5),D1 ;set filehandle
beq.b QuitSFile ;branch if not given
movea.l DOSBase(A5),A6 ;set DOS to call a function
jsr _LVOClose(A6) ;use DOS to (close) file
moveq #0,D0 ;clear filehandle
move.l D0,SHandle(A5)
tst.l SCount(A5) ;some bytes written ?
bne.b QuitSFile ;branch if so
move.l SortedFile(A5),D1 ;set filename
jsr _LVODeleteFile(A6) ;use dos to (delete) file
QuitSFile rts ;go back
*****************************************************************************
cnop 0,4
*********************************************** examine; read indexfile *****
GetIFile move.l IndexFile(A5),D1 ;get filename
move.l #MODE_OLDFILE,D2 ;file exists!
movea.l DOSBase(A5),A6 ;set dos_base
jsr _LVOOpen(A6) ;use dos to open file
move.l D0,IHandle(A5) ;save filehandle
beq Error2 ;branch if not found
;-----------------------------------------------
move.l IHandle(A5),D1 ;set filehandle
lea (A5),A3 ;get buffer for FIB
move.l A3,D2 ;set FileInfoBlock
jsr _LVOExamineFH(A6) ;use DOS to (examinefh)
tst.l D0 ;test for success
beq Error2 ;branch if not (close file)
;-----------------------------------------------
move.w #205,D1 ;preset rcode "not found.."
ext.l D1 ;clear highword
move.l fib_Size(A3),D0 ;set filesize
beq Error1 ;empty file?...
addq.l #2,D0 ;need one linefeed +
;null terminator at eof
addq.l #3,D0 ;get long aligned
andi.b #-4,D0 ;get long aligned
addq.l #4,D0 ;add room for security ID
moveq #0,D1 ;no options
movea.l 4.w,A6 ;set EXEC to call a function
jsr _LVOAllocMem(A6) ;use EXEC to (allocmem)
move.l D0,MemoryA(A5) ;save memorybase
beq Error2 ;branch if fail (close file)
;----------------------------------------------------------------------------
move.l IHandle(A5),D1 ;set filehandle (read)
movea.l MemoryA(A5),A2 ;get membase (endmark)
move.l A2,D2 ;set membase (read)
move.l fib_Size(A3),D3 ;set filesize (read)
;-----------------------------------------------
move.l D3,D0 ;get filesize
addq.l #2,D0 ;need one linefeed +
;null terminator at eof
addq.l #3,D0 ;get long aligned
andi.b #-4,D0 ;get long aligned
move.l #"EOF!",0(A2,D0.l) ;set security ID
;-----------------------------------------------
movea.l DOSBase(A5),A6 ;set DOS to call a function
jsr _LVORead(A6) ;use DOS to (read) bytes
cmp.l D0,D3 ;test for success
bne Error2 ;branch if fail (free mem)
;----------------------------------------------------------------------------
moveq #10,D0 ;get linefeed
lea -1(A2,D3.l),A0 ;jump to eof
cmp.b (A0)+,D0 ;check for linefeed
beq.b .skip ;branch if set
move.b D0,(A0)+ ;add a linefeed at eof
.skip clr.b (A0) ;set eof_terminator
*********************************************** close indexfile *************
CloseIFile move.l IHandle(A5),D1 ;set filehandle
beq.b .skip
movea.l DOSBase(A5),A6 ;set DOS to call a function
jsr _LVOClose(A6) ;use DOS to (close) file
moveq #0,D0 ;clear filehandle
move.l D0,IHandle(A5)
.skip rts ;go back
*****************************************************************************
cnop 0,4
*********************************************** free memory (indexfile) *****
FreeMemA move.l MemoryA(A5),D1 ;get file memory
beq.b .skip ;branch if not set
movea.l D1,A1 ;set memory base
lea (A5),A0 ;get fileinfoblock
move.l fib_Size(A0),D0 ;set filesize
addq.l #2,D0 ;need one linefeed +
;null terminator at eof
addq.l #3,D0 ;get long aligned
andi.b #-4,D0 ;get long aligned
addq.l #4,D0 ;add room for security ID
movea.l 4.w,A6 ;set EXEC to call a function
jsr _LVOFreeMem(A6) ;use EXEC to (freemem)
moveq #0,D0 ;clear buffer
move.l D0,MemoryA(A5)
.skip rts ;go back
*****************************************************************************
cnop 0,4
*********************************************** free memory (indexlist) *****
FreeEList move.l EList(A5),D1 ;get elist memory
beq.b .skip ;branch if not set
movea.l D1,A1 ;set memory base
move.l ELSize(A5),D0 ;set size
movea.l 4.w,A6 ;set EXEC to call a function
jsr _LVOFreeMem(A6) ;use EXEC to (freemem)
moveq #0,D0 ;clear buffer
move.l D0,EList(A5)
.skip rts ;go back
*****************************************************************************
cnop 0,4
*********************************************** read user arguments *********
ReadArgs lea Template(pc),A1 ;get template
lea ArgArray(A5),A2 ;get arg_array
move.l A1,D1 ;set arg_template
move.l A2,D2 ;set array
moveq #0,D3 ;set args (unused)
movea.l DOSBase(A5),A6 ;set dos_base
jsr _LVOReadArgs(A6) ;use dos to readargs
move.l D0,RDArgs(A5) ;save returncode
beq Error2
rts ;else, go back
*****************************************************************************
Template dc.b "INDEXFILE/A,OUTPUTFILE/A",0
dc.b "WS=WRITESORTED/K,SKIP/N,C=CASE/S,R=REVERSE/S,S=SLOW/S",0
Header dc.b "ERROR",0
*****************************************************************************
cnop 0,4
*****************************************************************************
ChkArgs moveq #115,D1 ;preset errorcode "bad num.."
move.l SkipHead(A5),D0 ;get "SKIP/N" ptr.
beq.b .skip ;branch if not set
movea.l D0,A0 ;set buffer
tst.l (A0) ;check for wrong number
bmi.b Error1 ;branch if so
.skip moveq #116,D1 ;preset errorcode "wrong arg"
move.l OutputFile(A5),d0 ;one of both ptr. must set
or.l SortedFile(A5),D0
beq.b Error1 ;branch if not
rts ;go back
*****************************************************************************
cnop 0,4
************************************************ free argument buffer *******
FreeArgs move.l RDArgs(A5),D1 ;get arg_structure
beq.b .skip ;branch if not set
move.l DOSBase(A5),A6 ;set dos_base
jsr _LVOFreeArgs(A6) ;use dos to freeargs
moveq #0,D0 ;clear buffer
move.l D0,RDArgs(A5)
.skip rts ;go back
*****************************************************************************
cnop 0,4
*********************************************** print error information *****
Error3 move.w #304,D1 ;set errorcode "***Break"
ext.l D1 ;clear highword
bra.b Error1
Error2 moveq #0,D1 ;get errorcode by dos
Error1 addq #4,SP ;clear return_address
move.l D1,RCode2(A5) ;set errorcode
pea Quit(pc) ;set return_address
Error0 move.l RCode2(A5),D1 ;get errorcode
bne.b .skip ;branch if known!
movea.l DOSBase(A5),A6 ;set dos to call a function
jsr _LVOIoErr(A6) ;use dos to get (ioerr)
move.l D0,D1 ;get errorcode
move.l D1,RCode2(A5) ;set errorcode
.skip movea.l DOSBase(A5),A6 ;set dos_base
jsr _LVOSetIoErr(A6) ;use dos to set pr_result2
move.l RCode2(A5),D1 ;get errorcode
moveq #0,D2 ;prepare dos printfault
cmp.w #304,D1 ;check for break by user
beq.b .PrintFault ;branch if so
lea Header(pc),A2 ;get head_text 'ERROR:'
move.l A2,D2 ;set header
.PrintFault jsr _LVOPrintFault(A6) ;use dos to printfault
moveq #5,D0 ;set returncode rc=warn
move.l D0,RCode1(A5) ;save
rts ;go back
*****************************************************************************
ifd BSS_Section
SECTION ChkIndex_bss,BSS
elseif
cnop 0,4
endc
*****************************************************************************
DataBase ds.b BSS_Size
end of source **************************************************************